package se.dolkow.skola.datasakerhet.server.storage;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;


/**
 * Convenience class. Stores and reuses a user identity, deferring all actions 
 * to the real Storage object.
 *
 */
public class BoundStorage {
	
	private final Storage s;
	private final User u;
	
	public BoundStorage(Storage s, User u) {
		this.s = s;
		this.u = u;
	}
	
	public void writeTo(PrintWriter w) {
		s.writeTo(w);
	}
		
	
	public Division getDivision(String name) {
		return s.getDivision(name);
	}
	
	public User getUser() {
		return u;
	}
	
	/**
	 * @return all records u can read
	 */
	public ArrayList<Record> getRecords() {
		return s.getRecords(u);
	}
	
	public Record getRecord(int id) throws PermissionDeniedException {
		return s.getRecord(id, u);
	}
	
	/**
	 * @param r
	 * @return content, if authorized
	 * @throws PermissionDeniedException
	 */
	public String getContent(Record r) throws PermissionDeniedException {
		return s.getContent(r, u);
	}
	
	/**
	 * @param r
	 * @param newContent
	 * @throws PermissionDeniedException
	 * @throws IOException 
	 */
	public void setContent(Record r, String newContent) throws PermissionDeniedException, IOException {
		s.setContent(r, newContent, u);
	}
	
	/**
	 * @param p
	 * @param n
	 * @throws PermissionDeniedException
	 * @throws IOException 
	 */
	public Record createRecord(Patient p, Nurse n) throws PermissionDeniedException, IOException {
		return s.createRecord(p, n, null, u);
	}
	
	/**
	 * @param r
	 * @throws PermissionDeniedException
	 * @throws IOException 
	 */
	public boolean deleteRecord(Record r) throws PermissionDeniedException, IOException {
		return s.deleteRecord(r, u);
	}
	
	public Nurse getNurse(String name) {
		return s.getNurse(name);
	}
	
	public Patient getPatient(String name) {
		return s.getPatient(name);
	}
}
